//
//  LoadingTipView.m
//  yunmaipad
//
//  Created by wuzhixiong on 12-11-8.
//
//

#import "LoadingTipView.h"

@implementation LoadingTipView




- (id)init
{
    if (self = [super init]) {
        
         self.layer.cornerRadius = 5;
        
        self.backgroundColor = [UIColor colorWithRed:0.26 green:0.45 blue:0.86 alpha:0.7];
        
        app=[UIApplication sharedApplication];
        
        activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        
        [self addSubview:activityIndicator];
        
        tipLabel=[[UILabel alloc] init];
        tipLabel.textAlignment=NSTextAlignmentCenter;
        [tipLabel sizeToFit];
        tipLabel.text=@"正在加载...";
        tipLabel.textColor=[UIColor whiteColor];
        tipLabel.font=[UIFont systemFontOfSize:16];
        tipLabel.backgroundColor=[UIColor clearColor];
        [self addSubview:tipLabel];
        
       
        
    }
    return self;
    
}



- (id)initWithFrame:(CGRect)frame withTipName:(NSString *)tipName
{
    if (self = [super initWithFrame:frame]) {
        
         self.layer.cornerRadius = 5;
        
        self.backgroundColor = [UIColor colorWithRed:0.26 green:0.45 blue:0.86 alpha:0.7];
        
        app=[UIApplication sharedApplication];
        
        activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        
        [self addSubview:activityIndicator];

        tipLabel=[[UILabel alloc] init];
        tipLabel.textAlignment=NSTextAlignmentCenter;
        [tipLabel sizeToFit];
        
        if(nil!=tipName && ![@"" isEqualToString:tipName]){
           tipLabel.text=tipName;
        }
        else{
             tipLabel.text=@"正在加载...";
        }
        tipLabel.textColor=[UIColor whiteColor];
        tipLabel.font=[UIFont systemFontOfSize:16];
       
        tipLabel.backgroundColor=[UIColor clearColor];
        [self addSubview:tipLabel];
        
        [self setTipFrame];
        
    }
     return self;
}



-(void)setTipWithFrame:(CGRect)frame withTipName:(NSString *)tipName
{
    self.frame=frame;
    tipLabel.text=tipName; 
   [self setTipFrame];
}


-(void)setTipFrame{
    
    CGRect tipLabelRect= CGRectMake(10,0, self.frame.size.width-60, self.frame.size.height);
    
    tipLabel.frame=tipLabelRect;
    
    CGRect activityIndicatorRect= CGRectMake(self.frame.size.width- 40,(self.frame.size.height-30)/2, 30, 30);
   
    activityIndicator.frame=activityIndicatorRect;
    
}



-(void)showTip{
    
    self.hidden=NO;
    [activityIndicator startAnimating];
     activityIndicator.hidden=NO;
     app.networkActivityIndicatorVisible=!app.networkActivityIndicatorVisible;
    
}

-(void)hiddenTip{
    self.hidden=YES;
    [activityIndicator stopAnimating];
	 activityIndicator.hidden=YES;
 
     app.networkActivityIndicatorVisible=NO;
}

 

@end
